<template>
	<view>
		<!-- #ifdef APP-PLUS -->
		<view>
			<uni-nav-bar title="补充商家信息" left-icon="arrowleft" @clickLeft="back" :statusBar='true' :fixed="true"></uni-nav-bar>
		</view>
		<!-- #endif -->
		<view class="supplementary">
			<view class="supplementary-item">
				<view class="supplementary-item-label">充值类型<text style="color: #F02230; font-weight: bold;margin-left: 10rpx;">*</text></view>
				<view class="supplementary-item-input" style="border: none;">
					<radio-group @change="onRadioChange">
						<label class="radio" style="margin-right: 40rpx;"><radio value="0" color="#F02230" :checked="type === '0'" />充值</label>
						<label class="radio"><radio value="1" color="#F02230" :checked="type === '1'" />折扣</label>
					</radio-group>
				</view>
			</view>
			<view class="supplementary-item">
				<view class="supplementary-item-label">会员折扣<text style="color: #F02230; font-weight: bold;margin-left: 10rpx;">*</text></view>
				<view class="supplementary-item-input">
					<input v-model="vip1" placeholder="请输入VIP1折扣" />
				</view>
			</view>
			<view class="supplementary-item">
				<view class="supplementary-item-label">plus会员折扣 <text style="color: #F02230; font-weight: bold;margin-left: 10rpx;">*</text></view>
				<view class="supplementary-item-input">
					<input v-model="vip2" placeholder="请输入会员折扣折扣" />
				</view>
			</view>
			<view class="supplementary-item">
				<view class="supplementary-item-label">授信额度</view>
				<view class="supplementary-item-input">
					<input v-model="credit" placeholder="请输入授信额度" />
				</view>
			</view>
			<view class="supplementary-item">
				<view class="supplementary-item-label">开户行</view>
				<view class="supplementary-item-input">
					<input v-model="bankName" placeholder="请输入开户行" />
				</view>
			</view>
			
			
			<view class="supplementary-item">
				<view class="supplementary-item-label">开户名称</view>
				<view class="supplementary-item-input">
					<input v-model="accountName" placeholder="请输入开户名称" />
				</view>
			</view>
			<view class="supplementary-item">
				<view class="supplementary-item-label">银行账户</view>
				<view class="supplementary-item-input">
					<input v-model="bankAccount" placeholder="请输入银行账户" />
				</view>
			</view>
			<view class="supplementary-item">
				<view class="supplementary-item-label">账户类型</view>
				<view class="supplementary-item-input" style="border: none;">
					<radio-group @change="onRadioChangeAccountType">
						<label class="radio" style="margin-right: 40rpx;"><radio value="0" color="#F02230" :checked="accountType === '0'" />对私</label>
						<label class="radio"><radio value="1" color="#F02230" :checked="accountType === '1'" />对公</label>
					</radio-group>
				</view>
			</view>
			<button class="supplementary-btn active" @click="submitForm">完成</button>
		</view>
	</view>
</template>

<script>
	import { config } from '@/utils/config.js';
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
	export default {
		data() {
			return {
				id: '',
				type: '',
				vip1: '',
				vip2: '',
				credit: '',
				bankName: '',
				accountName: '',
				bankAccount: '',
				accountType: '',
			};
		},
		components: {
			uniNavBar
		},
		onLoad(e) {
			
			const token = uni.getStorageSync('d_token')
			if (!token) {
				uni.showToast({
					icon: 'none',
					title: '尚未登录, 请先登录'
				})
				setTimeout(() => {
					uni.removeStorageSync('d_role')
					uni.removeStorageSync('d_memberId')
					uni.removeStorageSync('d_token')
					uni.removeStorageSync('d_openId')
					uni.reLaunch({
						url: '../verificationcodelogin/verificationcodelogin'
					})
				}, 777)
				return false
			}
			this.id = e.id
			this._getDetailInfoById()
		},
		methods: {
			back() {
				uni.navigateBack({})
			},
			_getDetailInfoById() {
				uni.request({
					url: `${config.api_base_url}agent/agent/application/${this.id}`,
					header: {
						AUTH: 'ROBOT ' + uni.getStorageSync('d_token')
					},
					success: ((res) => {
						let { status, data } = res.data
						if (status.flag === true) {
							if (data.type) {
								this.type = data.type
							}
							if (data.rate) {
								this.vip1 = JSON.parse(data.rate).vip1
								this.vip2 = JSON.parse(data.rate).vip2
							}
							if (data.credit) {
								this.credit = data.credit
							}
							if (data.bankName) {
								this.bankName = data.bankName
							}
							if (data.accountName) {
								this.accountName = data.accountName
							}
							if (data.bankAccount) {
								this.bankAccount = data.bankAccount
							}
							if (data.accountType) {
								this.accountType = data.accountType
							}
						}
					}),
					fail: (() => {
						uni.showToast({
							icon: 'none',
							title: '查询数据失败, 网络异常'
						})
					})
				})
			},
			onRadioChange(e) {
				this.type = e.detail.value
			},
			onRadioChangeAccountType(e) {
				this.accountType = e.detail.value
			},
			submitForm() {
				const obj = {}
				if (this.type === '0' || this.type === '1') {
					obj.type = this.type
				}
				if (this.vip1) {
					obj.vip1 = this.vip1 + ''
				}
				if (this.vip2) {
					obj.vip2 = this.vip2 + ''
				}
				if (this.credit) {
					obj.credit = this.credit + ''
				}
				if (this.bankName) {
					obj.bankName = this.bankName + ''
				}
				if (this.accountName) {
					obj.accountName = this.accountName + ''
				}
				if (this.bankAccount) {
					obj.bankAccount = this.bankAccount + ''
				}
				if (this.accountType === '0' || this.accountType === '1') {
					obj.accountType = this.accountType
				}
				if (obj.type !== '0' && obj.type !== '1') {
					uni.showToast({
						icon: 'none',
						title: '请选择充值类型'
					})
					return false
				}
				if (!obj.vip1) {
					uni.showToast({
						icon: 'none',
						title: '请填写会员折扣'
					})
					return false
				}
				if (!obj.vip2) {
					uni.showToast({
						icon: 'none',
						title: '请填写plus会员折扣'
					})
					return false
				}
				uni.request({
					url: `${config.api_base_url}agent/agent/application/updateStore/${this.id}`,
					method: 'PUT',
					header: {
						AUTH: 'ROBOT ' + uni.getStorageSync('d_token')
					},
					data: obj,
					success: ((res) => {
						let { status, data } = res.data
						if (status.flag === true) {
							uni.showToast({
								icon: 'none',
								title: '补充完成'
							})
							setTimeout(() => {
								uni.navigateTo({
									url:'../merchantsapplylist/merchantsapplylist'
								})
							},777)
						} else {
							uni.showToast({
								icon: 'none',
								title: status.msg
							})
						}
					}),
					fail: (() => {
						uni.showToast({
							icon: 'none',
							title: '请求失败, 网络异常'
						})
					})
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	view,
	text,
	input {
		box-sizing: border-box;
	}

	.supplementary {
		width: 100%;
		padding: 0 20rpx;

		.supplementary-item {
			width: 100%;
			font-size: 32rpx;
			line-height: 48rpx;
			margin-bottom: 10rpx;

			.supplementary-item-label {
				margin-bottom: 20rpx;
			}

			.supplementary-item-input {
				border: 2rpx solid #999;
				padding: 4rpx 20rpx;

				input {
					width: 100%;
					height: 100%;
					font-size: 30rpx;
				}
			}
		}

		.supplementary-btn {
			width: 100%;
			color: #999;
			margin-top: 40rpx;

			&.active {
				background-color: #F02230;
				color: #fff;
			}
		}
	}
</style>
